(function() {
  "use strict";
  APP.Views.GroupListRowView = Backbone.View.extend({
    tagName: 'tr',
    events : {
      'click .removeUserGroup': 'removeUserGroup'
    },
    initialize: function(params) {
      this.group = params.group;
    },
    removeUserGroup: function() {
      var callback = {
        obj: this,
        name: 'removeConfirmed'
      }
      new APP.Views.DialogMessageView({
        submitCallback: callback,
        body: APP.getTrans('ADD_USER_GROUP', 'CONFIRM_REMOVE')+'<strong>"'+this.group.userGroupName+'"</strong>?'
      }).render();
    },
    removeConfirmed: function() {
      var callback = {
        obj: this,
        name: 'removeUserGroupSuccess'
      }
      APP.BeClient.removeUserGroup(this.group.userGroupId, callback);
    },
    removeUserGroupSuccess: function() {
      this.remove();
    },
    attachEvents: function() {
      var self = this;
      this.$('input.activeCheckbox').on('ifChecked', function(e) {
        APP.BeClient.setGroupApplication(self.group.userGroupId, e.target.value, 'add');
      });
      this.$('input.activeCheckbox').on('ifUnchecked', function(e) {
        APP.BeClient.setGroupApplication(self.group.userGroupId, e.target.value, 'remove');
      });
    },
    render: function(reload) {
      this.$el.html(_.template($('#groupListRowTemplate').html(), {
        group: this.group
      }));
      this.$('input.activeCheckbox').iCheck({
        checkboxClass: 'icheckbox_brands-vgp',
        radioClass: 'iradio_brands-vgp',
        increaseArea: '20%' // optional
      });
      this.attachEvents();
      return this;
    }
  });
}());